package com.app.asktom.abs;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.widget.EditText;

public abstract class AbsHttpAsync extends AsyncTask<String, String, String>{
	
	protected Activity activity;
	protected ProgressDialog dialog;
	protected String dialogTitle;
	protected String response;
	protected boolean isShowLoading;
	
	public boolean isShowLoading() {
		return isShowLoading;
	}

	public void setShowLoading(boolean isShowLoading) {
		this.isShowLoading = isShowLoading;
	}

	public String getResponse() {
		return response;
	}

	public void setResponse(String response) {
		this.response = response;
	}

	public String getDialogTitle() {
		return dialogTitle;
	}

	public void setDialogTitle(String dialogTitle) {
		this.dialogTitle = dialogTitle;
	}

	@Override
	protected void onPreExecute() {
		super.onPreExecute();
		if(this.isShowLoading) {
			this.dialog = new ProgressDialog(this.activity);
			this.dialog.setTitle(this.dialogTitle);
			this.dialog.setMessage("Loading... Please wait");
			this.dialog.show();
		}
	}
	
	public Activity getActivity() {
		return activity;
	}

	public void setActivity(Activity activity) {
		this.activity = activity;
	}

	@Override
	protected void onPostExecute(String result) {
		// TODO Auto-generated method stub
		super.onPostExecute(result);
		if(this.isShowLoading) {
			this.dialog.dismiss();
		}
	}
	
	protected String getTextValue(int id) {
		EditText txt = (EditText) this.activity.findViewById(id);
		return txt.getText().toString();
	}
}
